<script>
	
	function cancel(){
		window.close();
	}
	function save(){
		//alert('test');
		$("#pelajaran_ke").removeAttr("disabled");
		$("#frmJadwalPelajaran").submit();		
	}
 
$(function(){
			$("#tingkatan_id").change(function(){
				var	dept=$("#department_id").val();
				var	karyawan_id=$("#karyawan_id").val();
				var	tahun_ajaran_id=$("#tahun_ajaran_id").val();
				var	tahun_ajaran_name=$("#tahun_ajaran_name").val();				
				var	tingkatan_id=$("#tingkatan_id").val();
				var	pelajaran_id=$("#pelajaran_id").val();
				var	hari=$("#hari").val();																								
				var	pelajaran_ke=$("#pelajaran_ke").val();																												
				var	pelajaran_sampai=$("#pelajaran_sampai").val();	
				var	karyawan_name=$("#karyawan_name").val();	 																															
				var	status=$("#status").val();	
				var	op=$("#op").val();	
				var	id=$("#id").val();									
				window.location.replace("index.php?r=akademik/guru_pelajaran/jadwal_pelajaran/form&id="+id+"&op="+op+"&department_id="+dept+"&karyawan_id="+karyawan_id+"&karyawan_name="+karyawan_name+"&tahun_ajaran_name="+tahun_ajaran_name+"&tahun_ajaran_id="+tahun_ajaran_id+"&pelajaran_ke="+pelajaran_ke+"&pelajaran_sampai="+pelajaran_sampai+"&hari="+hari+"&tingkatan_id="+tingkatan_id+"&pelajaran_id="+pelajaran_id+"&status="+status);
			});
			 
 								
		});	
	
	
	
</script>
<?php
	//echo $op;
	//print_r($op);
?>

<div style="border-bottom:2px solid #000;padding-bottom:5px;margin-bottom:20px">
<?php 
	$this->widget('application.components.widgets.ActionBar', 
		array("menuAlign" => "right", 
			'items' => array(
				array(
					'id' => "btnRefresh",
					'title' => "Simpan",
					'icon' => "images/action/Actions-document-save-all-icon.png",
					'callback'=>"save"
				),					
				array(
					'id' => "btnCancel",
					'title' => "Batal",
					'icon' => "images/action/Actions-dialog-cancel-icon.png",
					'callback'=>"cancel"
				),
			)
		)
	);
?>
</div>

 
 

<form id="frmJadwalPelajaran" action="index.php?r=akademik/guru_pelajaran/jadwal_pelajaran/edit" method="POST" >	
	<input type="hidden" name="op" id="op" value="<?php echo $op ?>" readonly/>
	<input type="hidden" name="id" id="id" value="<?php echo $id ?>" readonly/>
 
	<div>
	<?php
	$karyawan_name = Yii::app()->request->getParam("karyawan_name","");
	$tahun_ajaran_name = Yii::app()->request->getParam("tahun_ajaran_name","");
	$pelajaran_id = Yii::app()->request->getParam("pelajaran_id","");		
	$karyawan_id = Yii::app()->request->getParam("karyawan_id","");	
	$tahun_ajaran_id = Yii::app()->request->getParam("tahun_ajaran_id","");	
	$hari = Yii::app()->request->getParam("hari","");		
	$kelas_id = Yii::app()->request->getParam("kelas_id","");		
	$pelajaran_sampai = Yii::app()->request->getParam("pelajaran_sampai","");	
	$status = Yii::app()->request->getParam("status","");		 
		
 
		$this->widget('application.components.widgets.TextField', 
			array("name"=>"karyawan_name",
				"value"=>$karyawan_name,
				"htmlOptions"=>"size='20'",
				"htmlOptions"=>"disabled",				
				"label"=>array(
					"value"=>Yii::t("label","Guru"),
					"htmlOptions"=>"class='form' style='width:100px;'"
				)
			)
		);
	?>
	</div>
	<div>
		<input type="hidden" id="pelajaran_id" name="pelajaran_id" value="<?php echo $pelajaran_id ?>"/>    
		<input type="hidden" id="karyawan_id" name="karyawan_id" value="<?php echo $karyawan_id ?>"/>    
		<input type="hidden" id="department_id" name="department_id" value="<?php echo $department_id ?>"/>
		<input type="hidden" id="tahun_ajaran_id" name="tahun_ajaran_id" value="<?php echo $tahun_ajaran_id ?>"/>     
		<input type="hidden" id="hari" name="hari" value="<?php echo $hari ?>"/>                

		<?php
			$rsDep = MDepartment::model()->findAll(array("condition"=>"is_active = TRUE","order"=>"id"));
			$arrOptions=array();
			foreach($rsDep as $rw){
				$selected = $department_id == $rw->id ? true : false;
				$arrOptions[] = array("label"=>$rw->name,"value"=>$rw->id,"selected"=>$selected);
			}
			$this->widget('application.components.widgets.SelectField', 
				array("name"=>"department_id",
					"value"=>"",
					"htmlOptions"=>"disabled",
					"label"=>array(
						"value"=>"Department",
						"htmlOptions"=>"class='form mandatory' style='width:100px;'"
					),
					"options"=>$arrOptions,
				)
			);
			
		?>		
	</div>    
<div>
	<?php
		$this->widget('application.components.widgets.TextField', 
			array("name"=>"tahun_ajaran_name",
				"value"=>$tahun_ajaran_name,
				"htmlOptions"=>"size='20'",
				"htmlOptions"=>"disabled",
				"label"=>array(
					"value"=>Yii::t("label","Tahun"),
					"htmlOptions"=>"class='form' style='width:100px'"
				)
			)
		);
	?>
	</div>	 
<div>
	 
		<?php
			$tingkatan_id = Yii::app()->request->getParam("tingkatan_id","");		
			$rsDep = MTingkatan::model()->findAll(array("condition"=>"is_active = TRUE and department_id='".$department_id."'","order"=>"id"));
			$arrOptions=array();
			foreach($rsDep as $rw){
				$selected = $tingkatan_id == $rw->id ? true : false;
				$arrOptions[] = array("label"=>$rw->name,"value"=>$rw->id,"selected"=>$selected);
				$tingkatan_id = $tingkatan_id == "" ? $rw->id : $tingkatan_id;
			}
			$this->widget('application.components.widgets.SelectField', 
				array("name"=>"tingkatan_id",
					"value"=>"",
					"htmlOptions"=>"enable",
					"label"=>array(
						"value"=>"Tingkat",
						"htmlOptions"=>"class='form mandatory' style='width:100px;'"
					),
					"options"=>$arrOptions,
				)
			);
			
		?>		
	</div>        
<div>
 
		<?php
	$mcon= Yii::app()->db;
		$sql1='select * from v_kelas_tahun_ajaran where  tahun_ajaran_id = '.$tahun_ajaran_id.' and tingkatan_id='.$tingkatan_id .' and is_active=True';
		$mJadwalPelajaran=$mcon->createCommand($sql1);		
		$rsDep=$mJadwalPelajaran->queryAll();
		$json = CJSON::encode($rsDep); 
		$arrjam = json_decode($json,true);					
		//$rsDep = MKelas::model()->findAll(array("condition"=>"is_active = TRUE and tingkatan_id=".$tingkatan_id,"order"=>"id"));
		$arrOptions=array();
		for ($xid=0; $xid<count($arrjam); $xid++)
		{
			$selected = $kelas_tahun_ajaran_id == $arrjam[$xid]["id"]  ? true : false;
			$arrOptions[] = array("label"=>$arrjam[$xid]["kelas_name"],"value"=> $arrjam[$xid]["id"],"selected"=>$selected);
		}
		$this->widget('application.components.widgets.SelectField', 
			array("name"=>"kelas_tahun_ajaran_id",
				"value"=>"",
				"htmlOptions"=>"enable",
				"label"=>array(
					"value"=>"Kelas",
					"htmlOptions"=>"class='form mandatory' style='width:100px;'"
				),
				"options"=>$arrOptions,
			)
		);
		
		?>		
	</div>        
<div>
		 
		<?php
//			$rsDep = MPelajaran::model()->findAll(array("condition"=>"is_active = TRUE and department_id='".$department_id."'","order"=>"id"));
		$mcon= Yii::app()->db;
		$sql1='select B.id as id,name,karyawan_id,department_id from m_pengajar_pelajaran A left join m_pelajaran B on A.pelajaran_id=B.id where  karyawan_id='.$karyawan_id .' and department_id="'.$department_id.'"';
		$mJadwalPelajaran=$mcon->createCommand($sql1);		
		$rsDep=$mJadwalPelajaran->queryAll();
		$json = CJSON::encode($rsDep); 
		$arrjam = json_decode($json,true);						
			$arrOptions=array();
			for ($xid=0; $xid<count($arrjam); $xid++)
			{
				$selected = $pelajaran_id == $arrjam[$xid]["id"] ? true : false;
				$arrOptions[] = array("label"=>$arrjam[$xid]["name"],"value"=> $arrjam[$xid]["id"],"selected"=>$selected);
			}
			$this->widget('application.components.widgets.SelectField', 
				array("name"=>"pelajaran_id",
					"value"=>"",
					"htmlOptions"=>"enable",
					"label"=>array(
						"value"=>"Pelajaran",
						"htmlOptions"=>"class='form mandatory' style='width:100px;'"
					),
					"options"=>$arrOptions,
				)
			);
		?>		
	</div>        
<div>

	<?php
switch ($hari) {
    case 1:
        $hari_name = 'Senin';
        break;
    case 2:
        $hari_name = 'Selasa';
        break;
    case 3:
        $hari_name = 'Rabu';
        break;
    case 4:
        $hari_name = 'Kamis';
        break;
    case 5:
        $hari_name = 'Jumat';
        break;
    case 6:
        $hari_name = 'Sabtu';
        break;
    case 7:
        $hari_name = 'Minggu';
        break;								
}	
		$this->widget('application.components.widgets.TextField', 
			array("name"=>"hari_name",
				"value"=>$hari_name,
				"htmlOptions"=>"size='20'",
				"htmlOptions"=>"disabled",				
				"label"=>array(
					"value"=>Yii::t("label","Hari"),
					"htmlOptions"=>"class='form mandatory' style='width:100px'"
				)
			)
		);
	?>
	</div>	     
<div>
	<?php 
$pelajaran_ke=$_GET['pelajaran_ke'];
$rsDep = MJamPelajaran::model()->findAll(array("condition"=>"is_active = TRUE","order"=>"id"));
			$arrOptions=array();
			foreach($rsDep as $rw){
				$selected = $pelajaran_ke == $rw->id ? true : false;
				$arrOptions[] = array("label"=>$rw->name,"value"=>$rw->id,"selected"=>$selected);
			}
			$this->widget('application.components.widgets.SelectField', 
				array("name"=>"pelajaran_ke",
					"value"=>"",
					"htmlOptions"=>"disabled",
					"label"=>array(
						"value"=>"Jam ke",
						"htmlOptions"=>"class='form mandatory' style='width:100px;'"					),
					"options"=>$arrOptions,
				)
			);		
	?> s/d 
<?php
			$rsDep = MJamPelajaran::model()->findAll(array("condition"=>"is_active = TRUE and id>=".$pelajaran_ke.' and department_id="'.$department_id.'"',"order"=>"id"));
			$arrOptions=array();
			foreach($rsDep as $rw){
				$selected = $pelajaran_sampai == $rw->id ? true : false;
				$arrOptions[] = array("label"=>$rw->name,"value"=>$rw->id,"selected"=>$selected);
			}
			$this->widget('application.components.widgets.SelectField', 
				array("name"=>"pelajaran_sampai",
					"value"=>"",
					"htmlOptions"=>"enable",
					"label"=>array(
						"value"=>"",
						"htmlOptions"=>""
					),
					"options"=>$arrOptions,
				)
			);
	?>    
	</div>	     
<div>
 
		<?php
			//$rsDep = MStatus::model()->findAll(array("condition"=>"is_active = TRUE","order"=>"id"));
 			
			$arrOptions=array();
			for ($data_status_id=1; $data_status_id<=3; $data_status_id++)
			{	
				switch ($data_status_id) {
					case 1:
						$data_status_name = 'Mengajar';
						break;
					case 2:
						$data_status_name = 'Asistensi';
						break;
					case 3:
						$data_status_name = 'Tambahan';
						break;
				}				
				$selected = $status == $data_status_id ? true : false;
				$arrOptions[] = array("label"=>$data_status_name ,"value"=>$data_status_id,"selected"=>$selected);
			}
			
			$this->widget('application.components.widgets.SelectField', 
				array("name"=>"status",
					"value"=>"",
					"htmlOptions"=>"enable",
					"label"=>array(
						"value"=>"Status",
						"htmlOptions"=>"class='form mandatory' style='width:100px;'"
					),
					"options"=>$arrOptions,
				)
			);
			
		?>		
	</div>        
    
	<div><?php $this->widget('application.components.widgets.TextAreaField', array("name"=>"keterangan","value"=>$keterangan,"htmlOptions"=>"style='width:300px;height:60px'","label"=>array("value"=>Yii::t("label","Keterangan"),"htmlOptions"=>"class='form' style='width:100px'")));?></div>	
<!--
<div> <label class="form" style="width:100px;">test</label> <input type="text" size="20" /> </div>
<div> <label class="form" style="width:100px;">test</label> <select>
<option value="1">data</option>
<option value="1">data</option></select></div>
-->
</form>

